<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
use Validator;
use Auth;
class ControlController extends Controller
{

    /**
     *后台管理登录页面显示
     * Display a listing of the resource.
     * @return \Illuminate\Http\Response
     */
    public function getLogin()
    {
        return view('admin.login');
    }

    /**
     * 获取from数据把数据与数据库对比对比判断登录
     * @param Request $request
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function postLogin(Request $request)
    {
        //获取from提交的信息
        $name = $request->name;
        $password = $request->password;
        //和数据库数据进行对比
       $data = DB::table('control')->where(['uname'=>$name, 'password'=>$password])->get();
        //判断是否有信息 登录 或返回
        if(empty($data)){
            return redirect("/admin/login");
        }else {
            return redirect("/admin/index");
        }
    }

    public function getLogout()
    {
        return redirect("/admin/login");
    }



}
